package com.example.mobile2021606163crw0507;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private RadioButton radBtnSupplier1;
    private RadioButton radBtnSupplier2;
    private RadioButton radBtnSupplier3;
    private RadioButton radBtnSupplier4;
    private Button btnSupplierSubmit;
    private TextView tvMainSupplierTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();
        btnSupplierSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取选中数据
               int radBtnID =  radioGroup.getCheckedRadioButtonId();
               RadioButton radioButton = findViewById(radBtnID);
               String supplierName = radioButton.getText().toString();
                //2.把数据放到intent中
                Intent intent = new Intent();
                intent.putExtra("supplier",supplierName);
                //3.回传数据
                setResult(RESULT_OK,intent);
                //4.关闭本Activity
                finish();
            }
        });
    }

    private void initView() {
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        radBtnSupplier1 = (RadioButton) findViewById(R.id.radBtnSupplier1);
        radBtnSupplier2 = (RadioButton) findViewById(R.id.radBtnSupplier2);
        radBtnSupplier3 = (RadioButton) findViewById(R.id.radBtnSupplier3);
        radBtnSupplier4 = (RadioButton) findViewById(R.id.radBtnSupplier4);
        btnSupplierSubmit = (Button) findViewById(R.id.btnSupplierSubmit);
        tvMainSupplierTitle = (TextView) findViewById(R.id.tvMainSupplierTitle);
    }
}